#include "customList.h"

void MergeList(List *La,List *Lb,List *Lc)
{
	int i,j,k;
	i=j=1;k=0;
	int La_Len = ListLength(La);
	int Lb_Len = ListLength(Lb);
	while(i<=La_Len&&j<=Lb_Len)
	{
		int ai = 0,bj = 0;
		GetElem(La,i,ai);GetElem(Lb,j,bj);
		if(ai<=bj)
		{
			ListInsert(Lc,++k,ai);
			i++;
		}
		else
		{
			ListInsert(Lc,++k,bj);
			j++;
		}
	}
	while(i<=La_Len)
	{
		int ai = 0;
		GetElem(La,i,ai);
		ListInsert(Lc,++k,ai);
		i++;
	}
	while(j<=Lb_Len)
	{
		int bj = 0;
		GetElem(Lb,j,bj);
		ListInsert(Lc,++k,bj);
		j++;
	}
}

int main()
{
	List *L1,*L2,*L3;
	L3 = (List *)malloc(sizeof(List));
	L3->pnext = NULL;
	createList(&L1,&L2,1);
	MergeList(L1,L2,L3);
	print(L3);
	return 0;
}
